var keystone = require('keystone');
// var mongoose = require('mongoose');
// var Schema = mongoose.Schema;
const _ = require('lodash');
var Types = keystone.Field.Types;
/**
 * authority Model
 * ==================
 */

var Authority = new keystone.List('Authority', {
    autokey: {from: '_id', path: 'permissionId', unique: true },
});
 
Authority.add({
    name: {type: String, required: true}, //权限名称
    permissionOperate: {type: String, required: false}, //路径
    permissionCallback: {type: String, required: false}, //回调路径
    permissionNote: {type: String, required: false}, //备注
	parent: {type: Types.Relationship, ref: 'Authority', many: true}, //父ID
	children: {type: Types.Relationship, ref: 'Authority', many: true}, //ID
    status: {type: Types.Select, options: 'used, disable, delete', default: 'used'},
    //权限
    permissions: {type: String, required: false}
});
// Authority.schema.pre('find', function(next) {
// 	// this.populate('children');
// 	console.log(_.keys(this));
// 	console.log(_.keys(this.mongooseCollection));
// 	console.log(this);
// 	next();
//
// });
Authority.register();
